package com.aerotechnic.dao.implementation;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.aerotechnic.dao.interfaces.OutillageDaoIn;
import com.aerotechnic.entities.Mecanicien;
import com.aerotechnic.entities.Outillage;

@Repository("OutillageDao")
public class OutillageDao implements OutillageDaoIn {

	@Autowired
	private SessionFactory sessionFactory;

	private Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public void save(Outillage t) {

		// TODO Auto-generated method stub

		getCurrentSession().save(t);

	}

	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub

		Outillage e = findByID(id);
		if (e != null)
			getCurrentSession().delete(e);

	}

	@Override
	public Outillage findByID(int id) {
		// TODO Auto-generated method stub

		Session session = sessionFactory.getCurrentSession();

		return (Outillage) session.createQuery("FROM Outillage where id= " + id)
				.list().get(0);
	}

	@Override
	public void update(Outillage t) {
		// TODO Auto-generated method stub

		getCurrentSession().update(t);
	}

	public List<Outillage> findAll() {
		// TODO Auto-generated method stub

		return getCurrentSession().createQuery("from Outillage").list();
	}

}
